<?php
require_once 'config.php'; 
require_once 'Tools.class.php'; 
require_once 'User.class.php'; 
require_once 'HTML.class.php'; 
class Score{
    private $line1="-----------------\n";
    private $line2="===============\n";
	
    //获取本学期成绩
    function getThis($openid){
        $xn = XN;
        $xq = XQ;
        $xh = User::getXH($openid);
        $code = Tools::getHttp(DZU_URL."score.asp?&xn=".$xn."&xq=".$xq."&xh=".$xh."&ls=".CJLS);
        return $this->getScore($code,$xn,$xq);
    }

    //获取上学期成绩
    function getLast($openid){
        $x  = explode("-",XN);
        $xn = ($x[0]-1)."-".($x[1]-1);
        $xq = XQ==1?2:1;
        $xh = User::getXH($openid);
        $code = Tools::getHttp(DZU_URL."score.asp?&xn=".$xn."&xq=".$xq."&xh=".$xh."&ls=".CJLS);
        return $this->getScore($code,$xn,$xq);
    }
    
    function getScore($code,$xn,$xq){
    	$code = trim($code);
		$cjb = explode("@CJB",$code);
        $strTitle = "第".$xn."学年 \n第".$xq."学期成绩单\n".$this->line2;
        for($i=1;count($cjb)>$i;$i++){
            $kcmc = Tools::getInfo($cjb[$i],"KCMC");
            $zzcj = Tools::getInfo($cjb[$i],"ECJ");
            $jd = Tools::getInfo($cjb[$i],"JD");
        	$bq   = $jd=="0"?"[衰]":"[微笑]";
        	if($kcmc==NULL) continue;
        	$str .= "课程：".$kcmc;
        	$str .= "\n成绩：".$bq.$zzcj;
        	$str .= "\n".$this->line1;
    	}
        if($str!=""){
            $str = $strTitle.substr($str,0,-(strlen($this->line1)));
        }else{
            $str=$strTitle."暂无本学期成绩";
        }
    	
    	return $str;
    }

    function getScore_more($openid,$xn,$xq){
        $xh = User::getXH($openid);
        $nj=substr($xh, 0,4);
        $nj=(int)$nj;
        if($xn=='')$xn=$nj.'-'.($nj+1);
        if($xq=='')$xq=1;
        $code = Tools::getHttp(DZU_URL."score.asp?&xn=".$xn."&xq=".$xq."&xh=".$xh."&ls=".CJLS);
        $code = trim($code);
        $cjb = explode("@CJB",$code);
        for($i=1;count($cjb)>$i;$i++){
            $KCMC = Tools::getInfo($cjb[$i],"KCMC");
            $KCXZ = Tools::getInfo($cjb[$i],"KCXZ");
            $XF = Tools::getInfo($cjb[$i],"XF");
            $PSCJ = Tools::getInfo($cjb[$i],"PSCJ");
            $QZCJ = Tools::getInfo($cjb[$i],"QZCJ");
            $QMCJ = Tools::getInfo($cjb[$i],"QMCJ");
            $SYCJ = Tools::getInfo($cjb[$i],"SYCJ");
            $ECJ = Tools::getInfo($cjb[$i],"ECJ");
            $BKCJ = Tools::getInfo($cjb[$i],"BKCJ");
            $CXCJ = Tools::getInfo($cjb[$i],"CXCJ");
            $BZ = Tools::getInfo($cjb[$i],"BZ");
            $jd = Tools::getInfo($cjb[$i],"JD");

            $info.="课程名称：".$KCMC.'<br />';
            $info.="课程性质：".$KCXZ.'<br />';
            $info.="学&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分：".$XF.'<br />';
            $info.="成&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;绩：".$ECJ.'<br />';
            if($PSCJ!='null'){
                $info.="平时成绩：".$PSCJ.'<br />';   
            }
            if($QZCJ!='null'){
                $info.="期中成绩：".$QZCJ.'<br />';   
            }
            if($QMCJ!='null'){
                $info.="期末成绩：".$QMCJ.'<br />';   
            }
            if($SYCJ!='null'){
                $info.="实验成绩：".$SYCJ.'<br />';   
            }
            if($BKCJ!='null'){
                $info.="补考成绩：".$BKCJ.'<br />';   
            }
            if($CXCJ!='null'){
                $info.="重修成绩：".$CXCJ.'<br />';   
            }
            if($BZ!='null'){
                $info.="备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：".$BZ.'<br />';   
            }

            $info.="绩&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点：".$jd.'<br />';
            $image = $jd=="0"?"false.png":"true.png";
            $str .= HTML::makeList($image,$KCMC,$KCXZ.'@'.$ECJ,$info);
            $info="";
        }
        if($str==''){
            $str=HTML::makeListNULL("暂无本学期成绩");
        }
        $tpl=file_get_contents(API_URL."weixin/web/list.html");
        $tpl=str_replace("_FORM", $this->getFrom($openid,$xn,$xq), $tpl);
        $tpl=str_replace("_TITLE", '成绩查询', $tpl);
        $tpl=str_replace("_LIST", $str, $tpl);
        return $tpl;
    }

    function getFrom($oid,$xn,$xq){
        $xh = User::getXH($oid);
        $nj=substr($xh, 0,4);
        $nj=(int)$nj;
        $str.='<form action="" method="get">';
        $str.='&nbsp;&nbsp;';
        $str.='<select name="xn" class="xn" >';
        for($i=$nj;$i<$nj+4;$i++){
            if(substr($xn, 0,4)==$i){
                $select='selected="selected"';
            }else{
                $select="";
            }
           $str.='<option '.$select.' value="'.$i.'-'.($i+1).'">学期:'.$i.'-'.($i+1).'</option>'; 
        }
        $str.='</select>';
        $str.='<select name="xq" class="xq">';
        if($xq=='1'){
            $str.='<option selected="selected" value="1">学期:上学期</option>';
            $str.='<option value="2">学期:下学期</option>'; 
        }else{
            $str.='<option value="1">学期:上学期</option>';
            $str.='<option selected="selected" value="2">学期:下学期</option>';
        }
        
        $str.='</select>';
        $str.='<input type="hidden" name="opid" value="'.$oid.'" />';
        $str.='<input type="hidden" name="action" value="cjcx" />';
        $str.='<input class="cbtn" type="submit" name="submit" value="查询" />';
        $str.='</form>';

        return $str;
    }
}
?>